package net.sxnic.ugr.permission.action;

/**
 * @version $Revision$
 * @author 张国业 create 2013-4-15
 */

import net.sxnic.ugr.permission.Permission;

import org.apache.commons.lang3.StringUtils;
 
 


@SuppressWarnings("serial")
public class Save extends PermissionAction {
	

	public void prepare() throws Exception {
		if(StringUtils.isNotBlank(id))
			permission = authorizationManager.getPermissionById(id);
	}

	public String execute() throws Exception {
		
		 try {						
			 checkRoles(Permission.SYSTEM_ADMIN);
			  
//				// 角色
//				if (StringUtils.isBlank(menu)) {
//					permission.getMenus().clear();
//					 
//				} else {
//					 
//					String[] menus = StringUtils.split(menu, ",");
//					permission.getMenus().clear();
//					Menu m= null;
//					for (String rr : menus) {
//						m = authorizationManager.getMenu (rr.trim());
//						logger.debug("Menu id :" + m.getId() + " , Permission id :"
//								+ permission.getId());
//
//						permission.getMenus().add(m);
//						 
//					}
//					//user.setRoleCodes(StringUtils.removeEnd(tempCodes, ","));
//				} 
			 
			 	if(StringUtils.isNotBlank(resId)){
			 		permission.setRes(resourceManager.get(resId));
			 	}

			 	if(StringUtils.isBlank(permission.getId()))
			 		authorizationManager.createPermission(permission);
			 	else
			 		authorizationManager.updatePermission(permission);
	
				// 保存成功信息并转向
		        msg = "saveSuccess";
				
			} catch (Exception e) {
				e.printStackTrace();
			}
 	    return SUCCESS;
		
	}
		
}

	 
	 
